<?
$table="";
$tb_info="";
if(array_key_exists($_POST["cases"], $db_array)){
    $sql="SHOW TABLE STATUS LIKE '".$db_array[$_POST["cases"]]."'";
    $result=mysql_fetch_array(mysql_query($sql, $conn_db));
    $tb_info=$result["Comment"];
    $sql="SELECT * FROM ".$db_array[$_POST["cases"]]." WHERE web_grp<11 ORDER BY web_grp";
    $result=mysql_query($sql, $conn_db);
    if(mysql_error()){
	$sql="SELECT * FROM ".$db_array[$_POST["cases"]];
	$result=mysql_query($sql, $conn_db);
    }
    $old_web_grp=0;
    while($res=mysql_fetch_array($result)){
	$checked="";
	$disabled="";
	$dis="";
	if($res["commented"]==1){
	    $checked="checked";
	    $disabled="disabled";
	}
	($res["var_name_rus"]!="")?$res["var_name"]=$res["var_name_rus"]." [".$res["var_name"]."]":$res["var_name"]=$res["var_name"];
	$tmp="";
	if(preg_match("/^!/", $res["possible_val"])){
	    $disabled="disabled";
	    $dis="disabled";
	}
	if(array_key_exists($res["possible_val"], $vars_array)){
	    $tmp="onclick=\"operatedInput(this.name,'".$vars_array[$res["possible_val"]]."');\"";
	}
        $input="&nbsp;<input id=\"".$_POST["cases"]."_".$res["id"]."\" type=\"text\" value=\"".$res["var_val"]."\" name=\"".$_POST["cases"]."_".$res["id"]."\" onblur=\"post_var(this.name,this.value);\" ".$disabled." class=\"input\" ".$tmp.">";
	if(preg_match("!,!", $res["possible_val"])){
	    $input="&nbsp;<select id=\"".$_POST["cases"]."_".$res["id"]."\" name=\"".$_POST["cases"]."_".$res["id"]."\"  onblur=\"post_var(this.name,this.value);\" ".$disabled." class=\"select\">";
	    $tmp=explode(",",$res["possible_val"]);
	    foreach($tmp as $i=>$ii){
		if($res["var_val"]==$ii)
    		    $input.="<option selected value=\"".$ii."\">".$ii."</option>";
		else
    		    $input.="<option value=\"".$ii."\">".$ii."</option>";
	    }
    	    $input.="</select>";		
	}
	if(preg_match("!#!", $res["possible_val"])){
	    $dis="disabled";
	    $input="<table width=\"154\" align=\"left\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td>";
	    $tmp=explode("#", $res["possible_val"]);
	    $tmp1=explode(",", $res["var_val"]);
	    foreach($tmp as $i=>$ii){
		$check="";
		if($ii=="")continue;
		if(in_array($ii, $tmp1))$check="checked";
		$input.="<input id=\"cod".$i."\" type=\"checkbox\" ".$check." name=\"cod".$i."\" value=\"".$ii."\" class=\"check\" onclick=\"post_codecs('".$_POST["cases"]."_".$res["id"]."');\"><font class=\"z11\" size=\"-1\">".$ii."</font><br>\n";
	    }
	    $input.="</td></tr></table>";
	}
	if($old_web_grp!=$res["web_grp"]){
	    $table.="<tr><td height=\"10\" colspan=\"2\" style=\"border-right: 1px solid #c0c0c0;border-bottom: 1px solid #c0c0c0;\" align=\"left\" width=\"500\" bgcolor=e0e0e0>&nbsp;</td></tr>\n";
	}
	$table.="<tr>\n\t<td align=\"left\" valign=\"middle\" height=\"20\" style=\"border-right: 1px solid #c0c0c0;border-bottom: 1px solid #c0c0c0;\" align=\"left\" width=\"500\">"
        	."<font class=\"z11\" size=\"-1\">&nbsp;"
        	.$res["var_name"]."&nbsp;</font></td>\n\t"
        	."<td height=\"20\" style=\"border-right: 1px solid #c0c0c0;border-bottom: 1px solid #c0c0c0;\" align=\"left\" width=\"200\">"
        	."<font class=\"z11\" size=\"-1\">".$input
        	."&nbsp;"
        	."<input type=\"checkbox\" name=\"".$_POST["cases"]."\" value=\"".$res["id"]."\" ".$checked." title=\"Комментарий\" onclick=\"post_var_comment(this.name,this.value);\" ".$dis." class=\"check\">"
		."&nbsp;<a onclick=\"print_help('".$_POST["cases"]."', '".$res["id"]."');\">"
		."<img border=\"0\" alt=\"\" src=\"/images/icon_question.gif\" />"
		."</a><div id=\"note_".$res["id"]."\"></div>"
        	."</font></td>\n</tr>\n";
		    $old_web_grp=$res["web_grp"];
		}
	$table=xparse("tpl/tables.html");
    }
else{
    $tb_info="Ошибка чтения данных";
}
?>